package cloud.common.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@ApiModel("响应结果")
@Getter
@Setter
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("响应编码：0 成功；1 失败")
    private int code = 0;

    @ApiModelProperty("响应状态")
    private String msg = "success";

    @ApiModelProperty("响应数据")
    private T data;

    public Result<T> ok(T data) {
        this.data = data;
        return this;
    }

    public Result<T> error(String msg) {
        this.msg = msg;
        this.code = 1;
        return this;
    }
}
